package cn.cq.admin.controller;

import cn.cq.admin.entity.dto.BatchRemove;
import cn.cq.admin.entity.dto.UserCourseBatchDto;
import cn.cq.admin.entity.model.UserCourseBatch;
import cn.cq.admin.entity.vo.CourseVo;
import cn.cq.admin.entity.vo.UserCourseBatchVo;
import cn.cq.admin.service.UserCourseBatchService;
import cn.dev33.satoken.util.SaResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/userCourseBatch")
public class UserCourseBatchController {
    @Resource
    private UserCourseBatchService userCourseBatchService;

    @PostMapping("/doList")
    public SaResult doList(@RequestBody UserCourseBatchDto userCourseBatchDto) {
        Page<UserCourseBatchVo> voPage = userCourseBatchService.doList(userCourseBatchDto);
        return SaResult.data(voPage);
    }

    @PostMapping("/doSave")
    public SaResult doSave(@RequestBody UserCourseBatchDto userCourseBatchDto) {
        userCourseBatchService.doSave(userCourseBatchDto);
        return SaResult.ok("新增成功");
    }

    @PutMapping("/doModify")
    public SaResult doModify(@RequestBody UserCourseBatchDto userCourseBatchDto) {
        userCourseBatchService.doModify(userCourseBatchDto);
        return SaResult.ok("修改成功");
    }

    @DeleteMapping("/doRemove")
    public SaResult doRemove(@RequestBody BatchRemove batchRemove) {
        userCourseBatchService.doRemove(batchRemove.getIds());
        return SaResult.ok("删除成功");
    }

    @GetMapping("/doListCourseByUserId/{id}")
    public SaResult doListCourseByUser(@PathVariable Long id) {
        List<CourseVo> courseVos = userCourseBatchService.doListCourseByUser(id);
        return SaResult.data(courseVos);
    }
}
